package com.hamster.crmpre.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.mapper.EmployeeMapper;
import com.hamster.crmpre.pojo.Employee;
import com.hamster.crmpre.service.DepartmentIdQueryService;
import com.hamster.crmpre.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Tarry
 * @create 2020/1/12 21:40
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private DepartmentIdQueryService departmentIdQueryService;
    /**
     * 获取 员工select下拉框
     * @return
     */
    @Override
    public List<Employee> listEmployee() {
        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        employeeQueryWrapper.select("id","name","phone");
        employeeQueryWrapper.eq("del","0");
        List<Employee> list = employeeMapper.selectList(employeeQueryWrapper);
        return list;
    }

    @Override
    public List<Employee> listDepartmentEmployee() {
        LoginInterceptor.getLoginUser().getDepartment();
        String department = LoginInterceptor.getLoginUser().getDepartment();
        String departmentId= department.split(",")[0];

        QueryWrapper<Employee> employeeQueryWrapper = new QueryWrapper<>();
        employeeQueryWrapper.select("id","name","phone");
        employeeQueryWrapper.eq("del","0").eq("department",departmentId);
        List<Employee> list = employeeMapper.selectList(employeeQueryWrapper);
        return list;
    }
}
